<#include "/admin/_inc/_head.html"/>
<#include "/admin/_inc/_layout.html" />
<!DOCTYPE html>
<html lang="en">

<head>
    <@head />

</head>

<body>
    <@layout>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">

                    <div class="ibox-content">
                        <form id="form" class="form-horizontal m-t" method="post"
                              action="<#if model?exists>${ctx_admin}/role/update<#else>${ctx_admin}/role/add</#if>">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">
                                    角色名称
                                </label>
                                <div class="col-sm-8">
                                    <input type="hidden" name="roleId" value="${model.roleId}">
                                    <input type="text" placeholder="" name="roleName" class="form-control" required=""
                                           aria-required="true" value="${model.roleName}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">
                                    角色code
                                </label>
                                <div class="col-sm-8">
                                    <input minlength="2" type="text" class="form-control" name="roleCode" required=""
                                           aria-required="true" value="${model.roleCode}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">
                                    角色类型
                                </label>
                                <div class="col-sm-8">
                                    <select class="form-control" id="roleType" name="roleType">
                                        <option value="1">系统</option>
                                    </select>

                                </div>

                            </div>


                            <div class="form-group">
                                <label class="col-sm-3 control-label">
                                    角色级别
                                </label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" placeholder="" required="" aria-required="true"
                                           name="roleLevel" value="${model.roleLevel}">
                                </div>
                            </div>



                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3 text-center">
                                    <button id="btn-submit" class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

            </div>

        </div>


    </@layout>

<script src="/assets/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/assets/js/plugins/validate/messages_zh.min.js"></script>
<script src="/assets/js/plugins/jquery.form/jquery.form.js"></script>
<script type="text/javascript">
    $(function () {

        $("#form").validate({
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    type: 'post',
                    url: form.action,
                    success: function (data) {
                        if (data.success) {
                            layer.msg(data.message, {icon: 1, time: 2000}, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.$table.bootstrapTable('destroy');
                                parent.initTable();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(data.message, {icon: 2, time: 3000}, function () {
                            });
                        }
                    },
                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg('error!', {icon: 2, time: 3000}, function () {
                        });
                    }
                });
            }
        });

    });
</script>

</body>

</html>